package com.surfilter.controller;

import com.surfilter.bean.QueryResult;
import com.surfilter.service.IdentityConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author: lijia
 * @Date: Created in  2018-05-11 15:35
 * @Description:
 */
@Controller
public class IdentityConfigController {

    @Autowired
    private IdentityConfigService identityConfigService;

    @RequestMapping("/identityConfig")
    public String toVirtualType(){
        return "identityConfigManager";

    }


    @RequestMapping("/identityConfig/queryResult")
    @ResponseBody
    public Object getInfo(String page,String limit){

        QueryResult queryResult = new QueryResult();
//        queryResult.setAccount(account);
        queryResult.setPageNum(Integer.parseInt(page));
        queryResult.setLimit(Integer.parseInt(limit));
        return identityConfigService.queryTypeResult(queryResult);

    }


    @RequestMapping(value = "/identityConfig/delete/{id}",method = RequestMethod.POST)
    @ResponseBody
    public Object deteleVirtualTypeById(@PathVariable String id){
            int sum =  identityConfigService.deteleVirtualTypeById(id);
            if (sum ==1){
                return 1;
            }else {
                return 0;
            }
    }

    @RequestMapping("/identityConfig/addVirtualtype")
    @ResponseBody
    public Object addVirtualtype(@RequestParam("filename") MultipartFile file,String name){

        QueryResult queryResult = new QueryResult();
        queryResult.setVirtual_Name(name);
        queryResult.setIdentityConfig(file.getOriginalFilename());
        int i = identityConfigService.addVirtualtype(file,queryResult);
        return i;
    }


}
